package com.ycz.pattern.create.builderpattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @ClassName Meal
 * @Author yanchengzhi
 * @date 2023.11.21 00:32
 */
public class Meal {

    private List<Item> itemList = new ArrayList<>();
    // 菜单添加
    public void addItem(Item item) {
        itemList.add(item);
    }
    // 计价
    public float getCost() {
        Float cost = 0.0f;
        for(Item item:itemList) {
            cost += item.price();
        }
        return cost;
    }
    // 打印详细条目
    public void showItems() {
        for(Item item:itemList) {
            System.out.println("item:" + item.name() + ",packing:" + item.packing().pack() + ",price:" + item.price());
        }
    }

}
